package com.serviets;

import com.dao.AccountDao;
import com.dao.impl.AccountDaoimpl;
import com.model.CurAccount;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/account.do")
public class AccountServlet extends BaseServiets {
    //表现层
    private AccountDao accountDao=new AccountDaoimpl();
    protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String accountName = request.getParameter("account_name");
        String accountPassword = request.getParameter("account_password");
        System.out.println("accountName = " + accountName);
        System.out.println("accountPassword = " + accountPassword);
        CurAccount cur = accountDao.login(accountName, accountPassword);
        if (cur==null){
            request.setAttribute("errMsg","用户名为空，请重新登录");
            //跳转前端
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }else {
            if (cur.getAccount_status()==-1){
                request.setAttribute("errMsg","该账号被冻结，请联系管理员");
                request.getRequestDispatcher("login.jsp").forward(request,response);
            }else if (cur.getAccount_status()==1){
                request.setAttribute("errMsg","该用户不可用，已经作废");
                request.getRequestDispatcher("login.jsp").forward(request,response);
            }else{
                //正常运行
                request.getRequestDispatcher("book.do?operate=queryEmps").forward(request,response);
            }
        }

    }
}
//emp.do?operate=queryEmp"